﻿using NUnit.Framework;
using ThoughtWorks.CruiseControl.Core.Util;

namespace DevEnvXml.Tests
{
    public partial class DevenvXmlTaskResultTest
    {
        [Test]
        public void TestHeader()
        {
            string standardOutput = "------ Rebuild All started: Project: DevEnvXml, Configuration: Debug Any CPU ------";
            string expected = "<buildresults><project name=\"DevEnvXml\" configuration=\"Debug Any CPU\" /></buildresults>";

            ProcessResult result = new ProcessResult(standardOutput, "", 0, false);
            DevenvXmlTaskResult target = new DevenvXmlTaskResult(result);
            string testDataGet = Test_DataGet(target);
            Assert.AreEqual(expected, testDataGet, "Result XML");
        }

        [Test]
        public void TestBody()
        {
            string standardOutput =
                "------ Rebuild All started: Project: DevEnvXml, Configuration: Debug Any CPU ------" + "\n" +
                "text"
                ;
            string expected = "<buildresults><project name=\"DevEnvXml\" configuration=\"Debug Any CPU\"><message>text</message></project></buildresults>";

            ProcessResult result = new ProcessResult(standardOutput, "", 0, false);
            DevenvXmlTaskResult target = new DevenvXmlTaskResult(result);
            string testDataGet = Test_DataGet(target);
            Assert.AreEqual(expected, testDataGet, "Result XML");
        }

        [Test]
        public void Test2Projects()
        {
            string standardOutput =
                "------ Rebuild All started: Project: DevEnvXml, Configuration: Debug Any CPU ------" + "\n" +
                "p1 text1" + "\n" +
                "p1 text2" + "\n" +
                "------ Rebuild All started: Project: Prj2, Configuration: Debug Any CPU ------" + "\n" +
                "p2 text1" + "\n" +
                ""
                ;
            string expected = "<buildresults>" +
                "<project name=\"DevEnvXml\" configuration=\"Debug Any CPU\"><message>p1 text1</message><message>p1 text2</message></project>" +
                "<project name=\"Prj2\" configuration=\"Debug Any CPU\"><message>p2 text1</message></project>" +
                "</buildresults>";

            ProcessResult result = new ProcessResult(standardOutput, "", 0, false);
            DevenvXmlTaskResult target = new DevenvXmlTaskResult(result);
            string testDataGet = Test_DataGet(target);
            Assert.AreEqual(expected, testDataGet, "Result XML");
        }

        [Test]
        public void TestAllFinished()
        {
            string standardOutput = "========== Rebuild All: 1 succeeded, 2 failed, 3 skipped ==========";
            string expected = "<buildresults><finished buildtype=\"Rebuild All\" succeeded=\"1\" failed=\"2\" skipped=\"3\" /></buildresults>";

            ProcessResult result = new ProcessResult(standardOutput, "", 0, false);
            DevenvXmlTaskResult target = new DevenvXmlTaskResult(result);
            string testDataGet = Test_DataGet(target);
            Assert.AreEqual(expected, testDataGet, "Result XML");
        }

        [Test]
        public void TestCompleteAll()
        {
            string standardOutput =
                "------ Rebuild All started: Project: DevEnvXml, Configuration: Debug Any CPU ------" + "\n" +
                "p1 text1" + "\n" +
                "p1 text2" + "\n" +
                "------ Rebuild All started: Project: Prj2, Configuration: Debug Any CPU ------" + "\n" +
                "p2 text1" + "\n" +
                "========== Rebuild All: 2 succeeded, 0 failed, 999 skipped ==========" +
                ""
                ;
            string expected = "<buildresults>" +
                              "<project name=\"DevEnvXml\" configuration=\"Debug Any CPU\"><message>p1 text1</message><message>p1 text2</message></project>" +
                              "<project name=\"Prj2\" configuration=\"Debug Any CPU\"><message>p2 text1</message></project>" +
                              "<finished buildtype=\"Rebuild All\" succeeded=\"2\" failed=\"0\" skipped=\"999\" />" +
                              "</buildresults>" +
                              ""
                ;
            ProcessResult result = new ProcessResult(standardOutput, "", 0, false);
            DevenvXmlTaskResult target = new DevenvXmlTaskResult(result);
            string testDataGet = Test_DataGet(target);
            Assert.AreEqual(expected, testDataGet, "Result XML");
        }

    }
}
